<template>
  <div class="m-user">
    <template v-if="user">
      <nuxt-link to="/" class="m-user-name">{{user}}</nuxt-link>
      <nuxt-link to="/exit" class="m-user-exit">退出</nuxt-link>
    </template>
    <template v-else>
      <nuxt-link to="/login">立即登录</nuxt-link>
      <nuxt-link to="/register" class="m-user-register">注册</nuxt-link>
    </template>
  </div>
</template>

<script>
export default {
  data() {
    return {
      user: ''
    }
  },
  async mounted() {
    let res = await this.$store.dispatch('api/getUser')
    if (res.status === 200) {
      if (res.data && res.data.code === 0) {
        this.user = res.data.user
      }
    }
  }
}
</script>

<style lang="scss">
.m-user{
  .register{
    color: #999;
    &:hover{
      color: #FE8C00;
    }
  }
}
</style>